import React, { PureComponent } from "react"

export default class App extends PureComponent {
  constructor(props) {
    super(props)
    this.state = {
      username: '',
      password: '',
      valid: ''
    }
  }
  render() {
    return (
      <div>
        <form onSubmit={e => this.handleSubmit(e)}>
          <label htmlFor="username">
            用户:
            <input type="text"
              id="username"
              name="username"
              onChange={e => this.handleChange(e)}
              value={this.state.username}>
            </input>
          </label>
          <br />
          <label htmlFor="password">
            密码:
            <input type="text"
              id="password"
              name="password"
              onChange={e => this.handleChange(e)}
              value={this.state.password}></input>
          </label>
          <br />
          <label htmlFor="valid">
            验证:
            <input type="text"
              id="valid"
              name="valid"
              onChange={e => this.handleChange(e)}
              value={this.state.valid}>
            </input>
          </label>
          <br />
          <input type="submit" value="提交" />
        </form>
      </div>
    )
  }
  handleSubmit(event) {
    event.preventDefault()
    const { username, password, valid } = this.state
    console.log(username, password, valid);
  }
  handleChange(event) {
    console.log('触发');
    console.log('event----', event.target);
    this.setState({
      [event.target.name]: event.target.value
    })
  }
}